/**
 * Created by user on 2017/5/17.
 */
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;


public class OutToTxt {
    private static BufferedWriter writer;
    private static Scanner sc;

    public static void main(String[] args) {
        File out = new File("./Out.txt");
        if(!out.exists()) {
            try {
                out.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        try {
            writer = new BufferedWriter(new FileWriter(out));
        } catch (IOException e) {
            e.printStackTrace();
        }

        sc = new Scanner(System.in);
        System.out.println("请输入文本内容，输入exit结束：");
        try {
            writer.write(""); // 清空文本
            String split = "";
            while(true) {
                String line = sc.nextLine();
                if(line.equalsIgnoreCase("exit")) {
                    break;
                }
                writer.append(split + line);
                split = "\r\n";
            }
        } catch (IOException e1) {
            e1.printStackTrace();
        } finally {
            if(null != writer) {
                try {
                    writer.flush();
                    writer.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}